package com.forte.controller;

import java.util.List;

import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.forte.productdao.Product;
import com.forte.productservice.ProductService;


@Controller
public class HomeController {
	
	@Autowired
	ProductService productService;


	@RequestMapping(value="/index.do")
	public String Home(Model model){
		List<Product> products = productService.findAllProduct();
		 model.addAttribute("products", products);
		 LogManager.getRootLogger().log(Level.INFO,"Entering the Home Page");
		return "product";
	}
	
	
	@RequestMapping(value="/product.do")
	 public String showHome(Model model)	 
	 {
		 List<Product> products = productService.findAllProduct();
		 model.addAttribute("products", products);
		 System.out.println("Going into product page");
		 return "product";
		 
	 }
	
	@RequestMapping(value="/signout.do")
	public String signOut(Model model){
		model.addAttribute("display", "Guest");
		model.addAttribute("sessionState", "end");
		return "product";
	}

}
